package com.smartjobs.action;

import java.util.ArrayList;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.smartjobs.bean.CourseBean;
import com.smartjobs.model.CourseModel;

@SuppressWarnings("serial")
public class TrainerAction extends ActionSupport {

	String courseName;
	String description;
	String noOfMonths;
	String cost;
	int courseID;

	public int getCourseID() {
		return courseID;
	}

	public void setCourseID(int courseID) {
		this.courseID = courseID;
	}

	ArrayList<CourseBean> courseList;

	public ArrayList<CourseBean> getCourseList() {
		return courseList;
	}

	public void setCourseList(ArrayList<CourseBean> courseList) {
		this.courseList = courseList;
	}

	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getNoOfMonths() {
		return noOfMonths;
	}

	public void setNoOfMonths(String noOfMonths) {
		this.noOfMonths = noOfMonths;
	}

	public String getCost() {
		return cost;
	}

	public void setCost(String cost) {
		this.cost = cost;
	}

	public String getAllCourses() {
		Map session = ActionContext.getContext().getSession();
		courseList = new ArrayList<CourseBean>();
		System.out.println("inside get all courses");
		CourseModel.getAllCourses(courseList,Integer.parseInt(session.get("trainerId").toString()));
		return SUCCESS;
	}

	@SuppressWarnings("rawtypes")
	public String insertCourse() {
		Map session = ActionContext.getContext().getSession();
		CourseBean course = new CourseBean();
		course.setCost(cost);
		course.setTrainerId(Integer.parseInt(session.get("trainerId")
				.toString()));
		course.setCourseName(courseName);
		course.setDescription(description);
		course.setNoOfMonths(noOfMonths);
		CourseModel.insertCourse(course);
		return SUCCESS;
	}

	public String deleteCourse() {
		System.out.println("CourseID: " + courseID);
		CourseModel.deleteCourse(courseID);
		return SUCCESS;
	}
}
